package com.kaifamiao.buffer;

public class StringBufferTest4 {

	public static void main(String[] args) {
		
		StringBuffer buffer = new StringBuffer();
		System.out.println( buffer.length() + " , " + buffer.capacity() );
		
		buffer.append( "又到饭点儿了，你不饿吗" );
		
		System.out.println( buffer.length() + " , " + buffer.capacity() );
		
		// 将字符缓冲区截断到与长度相同
		buffer.trimToSize();
		
		System.out.println( buffer.length() + " , " + buffer.capacity() );
		
		// 确保不比参数指定数值小
		buffer.ensureCapacity( 20 );
		
		System.out.println( buffer.length() + " , " + buffer.capacity() );
		
		System.out.println( buffer );
		
		buffer.setLength( 5 );
		System.out.println( buffer );
		buffer.append( "又要发愁吃什么饭了" );
		System.out.println( buffer );
		
		buffer.setLength( 0 );
		System.out.println( buffer.length() + " , " + buffer.capacity() );
		System.out.println( buffer );
		buffer.append( "滚蛋，吃饭" );
		System.out.println( buffer );
	}

}
